home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 25 / Cream of the Crop 25.iso / program / fpk65_66.zip / SOURCE / RTL / DOS / HEX.PP < prev    next >
Text File  |  1996-07-02  |  746b  |  39 lines

  1. unit Hex;
  2.  
  3. interface
  4.  
  5. function HexStr(val:LongInt;cnt:Byte):string;
  6. function BinStr(val:Word;cnt:Byte):string;
  7.  
  8. implementation
  9.  
  10. function HexStr(val:LongInt;cnt:Byte):string;
  11. const hexval:string[16]=('0123456789ABCDEF');
  12. var s:string[20];
  13.     l2,i:integer;
  14.     l1:longInt;
  15. begin
  16. s[0]:=char(cnt);
  17. L1:=longint($F) shl (4*(cnt-1));
  18. for i:=1 to cnt do begin
  19.     L2:=(Val and L1) shr (4*(cnt-i));
  20.     L1:=L1 shr 4;
  21.     s[i]:=hexval[L2+1];
  22. end;
  23. HexStr:=s;
  24. end;
  25.  
  26. function BinStr(val:Word;cnt:Byte):string;
  27. var s:string[16];
  28.     mask,i:word;
  29. begin
  30. s[0]:=char(cnt);
  31. mask:=word(1) shl (cnt-1);
  32. for i:=1 to cnt do begin
  33.   if (val and mask)<>0 then s[i]:='1' else s[i]:='0';
  34.   mask:=mask shr 1;
  35. end;
  36. BinStr:=s;
  37. end;
  38.  
  39. end.